﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TmallClient.Controls
{
    public partial class Paging : UserControl
    {
        
        public event EventHandler PageIndexChanged;

        public long PageNo
        {
            get;
            set;
        }

        public long PageCount
        {
            get;
            set;
        }

        public void SetPage(long pageNo, long pageCount)
        {
            this.PageNo = pageNo;
            this.PageCount = pageCount;
            lblSummary.Text = string.Format("{0}/{1}", PageNo, PageCount);
        }

        public Paging()
        {
            InitializeComponent();
        }

        private void Paging_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Button button = sender as Button;
            switch (button.Text)
            {
                case "首页":
                    PageNo = 1;
                    break;
                case "上一页":
                    PageNo = PageNo > 1 ? PageNo - 1 : 1;
                    break;
                case "下一页":
                    PageNo = PageNo < PageCount ? PageNo + 1 : PageCount;
                    break;
                case "末页":
                    PageNo = PageCount;
                    break;
                default:
                    break;
            }

            lblSummary.Text = string.Format("{0}/{1}", PageNo, PageCount);

            if (PageIndexChanged != null)
            {
                PageIndexChanged(sender, e);
            }
        }
    }
}
